package com.firebird.app.kotlin.stock.base

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Nullable
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import butterknife.ButterKnife
import butterknife.Unbinder
import com.firebird.app.kotlin.stock.myview.state_layout.OtherViewHolder
import com.firebird.app.kotlin.stock.utils.SharedPreferencesUtil
import java.util.*


/**
 * @author ljk
 * @date 2019/2/2.
 * Description：
 */
abstract class BaseFragment : Fragment() {
    private var unBinder: Unbinder? = null
    var mHolder: OtherViewHolder? = null
    var isNetWork = true
    var keyList: List<String> = ArrayList()
    var valueList: List<String> = ArrayList()
    var strUserid: String? = null
    override fun onCreate(@Nullable savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    @Nullable
    override fun onCreateView(inflater: LayoutInflater, @Nullable container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view = inflater.inflate(layoutId, container, false)
        unBinder = ButterKnife.bind(this, view)
        mHolder = OtherViewHolder(getActivity())
        strUserid = SharedPreferencesUtil.getInstance(getActivity())!!.getSP("debtorid")
        initView(view)
        return view
    }

    override fun onDestroyView() {
        super.onDestroyView()
        unBinder!!.unbind()
    }

    /**
     * 初始化视图
     *
     * @param view
     */
    protected abstract fun initView(view: View?)

    protected abstract val layoutId: Int
    protected fun toClass(context: Context, clazz: Class<out BaseMvpActivity<*>?>?) {
        val intent = Intent(context, clazz)
        context.startActivity(intent)
    }

    //带参数
    protected fun toClass(context: Context, clazz: Class<out BaseMvpActivity<*>?>?, bundle: Bundle?) {
        val intent = Intent(context, clazz)
        intent.putExtras(bundle)
        context.startActivity(intent)
    }

    protected fun toClass1(context: Context, clazz: Class<out BaseActivity?>?) {
        val intent = Intent(context, clazz)
        context.startActivity(intent)
    }

    protected fun toClass_Empty(context: Context, clazz: Class<out BaseActivity?>?) {
        val intent = Intent(context, clazz)
        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
        context.startActivity(intent)
    }

    protected fun toClass_EmptyTop(context: Context, clazz: Class<out BaseActivity?>?) {
        val intent = Intent(context, clazz)
        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
        context.startActivity(intent)
    }

    protected fun toClass(context: Context?, clazz: Class<out BaseMvpActivity<*>?>?, bundle: Bundle, reuqestCode: Int) {
        val intent = Intent(context, clazz)
        intent.putExtras(bundle)
        ActivityCompat.startActivityForResult(intent, reuqestCode)
    }

    protected fun toClass1(context: Context?, clazz: Class<out BaseActivity?>?, bundle: Bundle, reuqestCode: Int) {
        val intent = Intent(context, clazz)
        intent.putExtras(bundle)
        ActivityCompat.startActivityForResult(intent, reuqestCode)
    }

    protected fun toClass(context: Context?, clazz: Class<out BaseMvpActivity<*>?>?, reuqestCode: Int) {
        val intent = Intent(context, clazz)
        ActivityCompat.startActivityForResult(intent, reuqestCode)
    }

    protected fun toClass1(context: Context?, clazz: Class<out BaseActivity?>?, reuqestCode: Int) {
        val intent = Intent(context, clazz)
        ActivityCompat.startActivityForResult(intent, reuqestCode)
    }
}